package protocol;

import com.google.gson.Gson;

import java.nio.ByteBuffer;

/**
 * Created by Administrator on 2016/9/12.
 */
public class ProtoMsg {
    public String action;
    public String content;
    public ProtoMsg(){
    }

    public ProtoMsg(String act, String content){
        this.action = act;
        this.content = content;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String toJsonString(){
        Gson gson = new Gson();
        return gson.toJson(this);
    }

    public static ProtoMsg fromJson(String str){
        Gson gson = new Gson();
        return  gson.fromJson(str,ProtoMsg.class);
    }

    public ByteBuffer toBytes(){
        ProtoMsgEncoder encoder = new ProtoMsgEncoder(ProtoMsgEncoder.Notify,action,content.getBytes());
        return  encoder.toBytes();
    }
}
